<?php


class important extends connector {

	function important() {
		$this->softbase(true);
	}

	function onforumlist() {
		$this->powercheck(178, 179);
		parent::start_template();

		$MinPageid = $this->fun->accept('MinPageid', 'R');

		$page_id = $this->fun->accept('page_id', 'R');

		$countnum = $this->fun->accept('countnum', 'R');

		$MaxPerPage = $this->fun->accept('MaxPerPage', 'R');
		if (empty($MaxPerPage)) {
			$MaxPerPage = $this->CON['max_list'];
		}
		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;
		$db_where = ' WHERE lng=\'' . $lng . '\'';
		$noreply = $this->fun->accept('noreply', 'R');
		if (!empty($noreply)) {
			if ($noreply == 2) $noreply = 0;
			$db_where.=' AND noreply=' . $noreply;
		}
		$istop = $this->fun->accept('istop', 'R');
		if (!empty($istop)) {
			if ($istop == 2) $istop = 0;
			$db_where.=' AND istop=' . $istop;
		}
		$recommend = $this->fun->accept('recommend', 'R');
		if (!empty($recommend)) {
			if ($recommend == 2) $recommend = 0;
			$db_where.=' AND recommend=' . $recommend;
		}
		$isclass = $this->fun->accept('isclass', 'R');
		if (!empty($isclass)) {
			if ($isclass == 2) $isclass = 0;
			$db_where.=' AND isclass=' . $isclass;
		}
		$linkebid = $this->fun->accept('linkebid', 'R');
		if (!empty($linkebid)) {
			$db_where.=' AND linkebid=' . $linkebid;
			$MaxPerPage = $MaxPerPage - 1;
		} else {
			$db_where.=' AND linkebid=0';
		}
		$btid = $this->fun->accept('btid', 'R');
		if (!empty($btid)) {
			$db_where.=' AND btid=' . $btid;
		}
		$blid = $this->fun->accept('blid', 'R');
		if (!empty($blid)) {
			$db_where.=' AND blid=' . $blid;
		}
		$purview = $this->fun->accept('purview', 'R');
		if (!empty($purview)) {
			$db_where.=' AND purview=' . $purview;
		}
		$serchekey = $this->fun->accept('serchekey', 'R');
		if (!empty($serchekey)) {
			$db_where.=" AND title like '%$serchekey%'";
		}


		$limitkey = $this->fun->accept('limitkey', 'R');
		$limitkey = empty($limitkey) ? 'bid' : $limitkey;

		$limitclass = $this->fun->accept('limitclass', 'R');
		$limitclass = empty($limitclass) ? 'DESC' : $limitclass;
		$db_table = db_prefix . 'bbs';
		if (!empty($countnum)) {
			$countnum = $this->db_numrows($db_table, $db_where);
			exit($countnum);
		}
		$sql = 'SELECT * FROM ' . $db_table . $db_where . ' ORDER BY ' . $limitkey . ' ' . $limitclass . ' LIMIT ' . $MinPageid . ',' . $MaxPerPage;
		$rs = $this->db->query($sql);
		while ($rsList = $this->db->fetch_assoc($rs)) {
			$array[] = $rsList;
		}
		$this->fun->setcookie($this->fun->noncefile() . 'pgid', $page_id, 600);
		$this->ectemplates->assign('array', $array);
		$this->ectemplates->assign('linkebid', $linkebid);
		$this->ectemplates->assign('lng', $lng);
		$this->ectemplates->assign('noreply', $noreply);
		$this->ectemplates->assign('istop', $istop);
		$this->ectemplates->assign('recommend', $recommend);
		$this->ectemplates->assign('isclass', $isclass);
		$this->ectemplates->assign('btid', $btid);
		$this->ectemplates->assign('blid', $blid);
		$this->ectemplates->assign('limitkey', $limitkey);
		$this->ectemplates->assign('limitclass', $limitclass);
		$this->ectemplates->assign('sql', $sql);
		$this->ectemplates->display('forum/forum_list');
	}

	function onlist() {
		include_once admin_ROOT . adminfile . '/include/command_list.php';
		parent::start_template();
		$listfunction = $this->fun->accept('listfunction', 'G');
		if (empty($listfunction)) {
			exit('err');
		}
		$btid = $this->fun->accept('btid', 'R');
		$lng = $this->fun->accept('lng', 'G');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;
		$istop = $this->fun->accept('istop', 'R');
		$isclass = $this->fun->accept('isclass', 'R');
		$blid = $this->fun->accept('blid', 'R');
		$linkebid = $this->fun->accept('linkebid', 'R');
		$limitkey = $this->fun->accept('limitkey', 'R');
		$limitclass = $this->fun->accept('limitclass', 'R');
		$recommend = $this->fun->accept('recommend', 'R');
		$noreply = $this->fun->accept('noreply', 'R');

		$cookpage = $this->fun->accept($CONLIST[$listfunction]['pagecoock'], 'C');
		$nowpage = empty($cookpage) ? 0 : $cookpage;
		$this->ectemplates->assign('nowpage', $nowpage);
		$this->ectemplates->assign('loadurl', $CONLIST[$listfunction]['loadurl'] . '&btid=' . $btid . '&isclass=' . $isclass . '&blid=' . $blid . '&linkebid=' . $linkebid . '&istop=' . $istop . '&recommend=' . $recommend . '&noreply=' . $noreply . '&limitkey=' . $limitkey . '&limitclass=' . $limitclass);

		$this->ectemplates->assign('MaxPerPage', $this->CON['max_list']);

		$this->ectemplates->assign('MaxHit', $this->CON['max_page']);
		$this->ectemplates->assign('lng', $lng);
		$this->ectemplates->assign('listtype', $listtype);
		$this->ectemplates->assign('listfunction', $listfunction);
		$this->ectemplates->display('article/article_tab_list');
	}

	function onsearch() {
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng);
		$this->ectemplates->assign('lnglist', $lnglist['list']);
		$bbstype = $this->get_bbstype_array(0, $lng);
		$this->ectemplates->assign('bbstype', $bbstype['list']);
		$this->ectemplates->display("forum/forum_search");
	}

	function onedit() {
		$this->powercheck(178, 193);
		parent::start_template();
		$type = $this->fun->accept('type', 'G');
		$bid = $this->fun->accept('bid', 'G');

		$read = $this->get_bbs($bid);

		$forumtype = $this->get_bbstype_array($read['btid']);

		$memberpuv = $this->get_member_purview_array($read['purview']);
		$this->ectemplates->assign('memberpuvlist', $memberpuv['list']);
		$this->ectemplates->assign('tab', 'true');
		$this->ectemplates->assign('forumtype', $forumtype['list']);
		$this->ectemplates->assign('read', $read);
		$this->ectemplates->assign('type', $type);
		$this->ectemplates->display('forum/forum_edit');
	}

	function onsave() {
		parent::start_template();
		$inputclass = $this->fun->accept('inputclass', 'P');
		$lng = $this->fun->accept('lng', 'P');
		$btid = $this->fun->accept('btid', 'P');
		$linkebid = $this->fun->accept('linkebid', 'P');
		$title = $this->fun->accept('title', 'P');
		$content = $this->fun->accept('content', 'P');
		$purview = $this->fun->accept('purview', 'P');
		$keyword = $this->fun->accept('keyword', 'P');
		$db_table = db_prefix . 'bbs';
		$db_table2 = db_prefix . 'bbs_content';
		$date = time();
		if ($inputclass == 'edit') {
			$this->powercheck(178, 193);
			$bid = $this->fun->accept('bid', 'P');
			if (empty($bid)) exit('false');
			$db_where = 'bid=' . $bid;
			$db_set = "title='$title',keyword='$keyword',purview=$purview,updatetime=$date";
			$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			$db_set = "content='$content'";
			$this->db->query('UPDATE ' . $db_table2 . ' SET ' . $db_set . ' WHERE ' . $db_where);
			$this->writelog($this->lng['forummain_edit_log'], $this->lng['log_extra_ok'] . ' title=' . $title . ' id=' . $bid);
			$this->dbcache->clearcache('bbs_list_array_' . $btid, true);
			exit('true');
		}
	}

	function ondel() {
		$this->powercheck(178, 194);
		$db_table = db_prefix . 'bbs';
		$db_table2 = db_prefix . 'bbs_content';
		$selectinfoid = $this->fun->accept('articleselectinfoid', 'P');
		if (empty($selectinfoid)) exit('false');
		$infoarray = explode(',', $selectinfoid);
		$count = count($infoarray) - 1;
		if ($count <= 0) exit('false');
		for ($i = 0; $i < $count; $i++) {
			$db_where = "bid=$infoarray[$i]";
			$db_where2 = "linkebid=$infoarray[$i]";
			$this->db->query('DELETE FROM ' . $db_table . ' WHERE ' . $db_where);
			$this->db->query('DELETE FROM ' . $db_table . ' WHERE ' . $db_where2);
			$this->db->query('DELETE FROM ' . $db_table2 . ' WHERE ' . $db_where);
			$this->db->query('DELETE FROM ' . $db_table2 . ' WHERE ' . $db_where2);
		}
		$this->writelog($this->lng['forummain_del_log'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		$this->dbcache->clearcache('bbs_list_array', true);
		exit('true');
	}

	function onsort() {
		$this->powercheck(178, 196);
		$db_table = db_prefix . 'bbs';
		$id = $this->fun->accept('infoid', 'P');
		$pid = $this->fun->accept('pid', 'P');
		$idArray = explode(',', $id);
		$pidArray = explode(',', $pid);
		foreach ($idArray as $key => $value) {
			if (!empty($value)) {
				$db_where = "bid=$value";
				$pid = intval($pidArray[$key]);
				$db_set = "pid=$pid";
				$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			}
		}
		$this->writelog($this->lng['forummain_sort_log'], $this->lng['log_extra_ok']);
		$this->dbcache->clearcache('bbs_list_array', true);
		exit('true');
	}

	function onsetting() {
		$this->powercheck(178, 195);
		$db_table = db_prefix . 'bbs';
		$selectinfoid = $this->fun->accept('articleselectinfoid', 'P');
		$selectinfoid = $selectinfoid . '0';
		if (empty($selectinfoid)) exit('false');
		$value = $this->fun->accept('value', 'P');
		$dbname = $this->fun->accept('dbname', 'P');
		$db_set = "$dbname=$value";
		$db_where = "bid IN ( $selectinfoid )";
		$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
		$this->writelog($this->lng['forummain_class_log'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		$this->dbcache->clearcache('bbs_list_array', true);
		exit('true');
	}

}
?>